package com.yztstudy.Controller;

import com.yztstudy.Service.ProductService;
import com.yztstudy.entity.Product;
import com.yztstudy.param.ProductSaveParam;
import com.yztstudy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商品被类别调用的表示层
 */

@RestController
@RequestMapping("/product")
public class ProductCategoryController {

    @Autowired
    private ProductService productService;


    /**
     * TODO 查询某个类别是否有商品
     * @param categoryId 类别ID
     * @return
     */
    @PostMapping("/admin/count")
    public Long adminCount(@RequestBody Integer categoryId)
    {
        return productService.adminCount(categoryId);
    }


    /**
     * TODO 保存商品
     * @param productSaveParam 要保存的商品
     * @return
     */
    @PostMapping("/admin/save")
    public R adminSave(@RequestBody ProductSaveParam productSaveParam)
    {
        return productService.adminSave(productSaveParam);
    }


    /**
     * TODO 更新商品
     * @param product 商品对象
     * @return
     */
    @PostMapping("/admin/update")
    public R adminUpdate(@RequestBody Product product)
    {
        return productService.adminUpdate(product);
    }


    /**
     * TODO 删除商品
     * @param productId 商品Id
     * @return
     */
    @PostMapping("/admin/remove")
    public R adminRemove(@RequestBody Integer productId)
    {
        return productService.adminRemove(productId);
    }
}
